# coding: utf-8
import json

from common import EDGE_USER_AGENT
from .send import RequestBase


class MianKouTuAPI(RequestBase):
    base_url = 'https://wallpaper.soutushenqi.com'
    headers = {'User-Agent': EDGE_USER_AGENT}

    @classmethod
    def queryConfig(cls, config_key: str= 'mktp_atlas_new_category_list'):
        url = cls.base_url + '/v1/config/queryConfig'
        params = {
            'product_id': 53,
            'version_code': 1386,
            'config_key': config_key,
            # 'sign': '65E2660D469AF2A9D8BB300C868A4A55'
        }
        result = cls.post(url, params=params, headers=cls.headers).json()
        data = result.get('data', '{}')
        return json.loads(data)

    @classmethod
    def queryByTag(cls, tag: str, sort_type: int = 1, page: int = 0):
        url = cls.base_url + '/api/wallpaper/queryByTag'
        params = {
            'product_id': 53,
            'version_code': 1386,
            'tag': tag,
            'sort_type': sort_type,
            'page': page,
            'page_size': 30,
            'scene_type': 13,
            # 'sign': '2A7CF09BEA49EB367B1CB8C9BB9589C0'
        }
        result = cls.post(url, params=params, headers=cls.headers).json()
        return result

    @classmethod
    def commonList(cls, page: int = 0, sort_type: int = 0):
        url = cls.base_url + '/v2/search/commonList'
        params = {
            'product_id': 53,
            'version_code': 1386,
            'page': page,
            'sort_type': sort_type,
            'table_type': 3,
            # 'sign': '6BD69D0BDE80EE0467AEBC2E60419844'
        }
        result = cls.post(url, params=params, headers=cls.headers).json()
        return result
